﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem
{
    public partial class ListBoxProduct : System.Web.UI.Page
    {
        public static int sizePage;
        public static int type;
        public static int currentPage;
        public static DataTable dt;
        public static int AllCat;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                sizePage = Convert.ToInt32(ConfigurationManager.AppSettings["sizepage"].ToString());
              
                

                if (Request.QueryString["currentPage"] != null)
                {
                    if (Request.QueryString["type"] != null)
                        type= Convert.ToInt32(Request.QueryString["type"].ToString());
                    else
                        Response.Redirect("Error.aspx");



                    currentPage = Convert.ToInt32(Request.QueryString["currentPage"].ToString());
                    if(type==1)
                        
                        dt = BOL.ProductManager.Instance.GetListProductsPaging("tbl_Product", "selectorderbyallproduct", currentPage, sizePage, 0,
                                                                           "Product_Rank","DESC");
                    if(type==2)
                        dt = BOL.ProductManager.Instance.GetListProductsPaging("tbl_Product", "selectorderbyallproduct", currentPage, sizePage, 0,
                                                                          "Product_Discount", "DESC");
                }


                else
                {
                    if (Request.QueryString["type"] != null)
                        type = Convert.ToInt32(Request.QueryString["type"].ToString());
                    else
                        Response.Redirect("Error.aspx");


                    currentPage = 1;

                    if (type == 1)

                        dt = BOL.ProductManager.Instance.GetListProductsPaging("tbl_Product", "selectorderbyallproduct", currentPage, sizePage, 0,
                                                                           "Product_Rank","DESC");
                    if (type == 2)
                        dt = BOL.ProductManager.Instance.GetListProductsPaging("tbl_Product", "selectorderbyallproduct", currentPage, sizePage, 0,
                                                                          "Product_Discount","DESC");
                }


                // VIet stored dem so san pham co catID = CatID

                string name = "";
                if (type == 1) name = "Product_Rank";
                if (type == 2) name = "Product_Discount";


                AllCat = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.StoredProcedureSelectWhereByID("tbl_Product", name, 0, "selectcountwhere1").Rows[0]["count"].ToString());

              
            }
        }
    }
}